package com.fengwei.filter;

import com.google.gson.Gson;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author wei.feng
 * @date 2019-9-11
 */
@Component
@Aspect
public class ResponseAspectFilter {
    private static final Logger logger = LoggerFactory.getLogger(ResponseAspectFilter.class);

    @AfterReturning(returning = "object", pointcut = "execution( * com.fengwei.controller..*.*(..))")
    public void doAfterReturning(Object object) {
        Gson gson = new Gson();
        //日志量太大就不打印了
        if (gson.toJson(object).length() <= 10000) {
            logger.debug("return object:" + gson.toJson(object));
        } else {
            logger.debug("return object:" + gson.toJson(object).substring(0, 10000));
        }

    }
}
